import {defineStore} from "pinia";

export const userStore = defineStore({
    id: 'user',
    state: () => {
        return {
            userInfo: {
                avatar: "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png",
                username: "aaaa"
            },
            token: "123",
            lang: "zh",
            isCollapse: false
        }
    },
    getters: {},
    actions: {
        //登录
        login() {
            this.token = 'ada'
        },
        //退出
        loginOut() {
            this.$state.token = ""
        }
    },
    persist: {
        enabled: true, // 开启数据缓存
        strategies: [
            {
                key: 'user',
                storage: sessionStorage,// 默认是sessionStorage
                paths: ['token', 'userInfo', 'lang']
            }
        ],
    }
})